import 'package:flutter/material.dart';
import 'package:kxy_flutter_app/events/events.dart';
import 'package:kxy_flutter_app/model/exam_rank.dart';
import 'package:kxy_flutter_app/view/my/rank/user_rank_item_widget.dart';

class MyRankWidget extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _MyRankWidgetState();
  }
}

class _MyRankWidgetState extends State<MyRankWidget> {
  ExamRank rank;

  @override
  void initState() {
    super.initState();
    Events.instance.on<MyExamRankChanged>().listen((event) {
      setState(() {
        rank = event.rank;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    if (rank == null) return Container(height: 90);
    return Container(
      height: 90,
      color: Colors.transparent,
      margin: EdgeInsets.only(bottom: 5),
      child: UserRankItemWidget(
        rankItem: new ExamRankItem(
          realName: rank.realName,
          deptName: rank.deptName,
          headUrl: rank.headUrl,
          rank: rank.userRank,
          score: rank.userScore,
        ),
        isLight: true,
      ),
    );
  }
}
